package com.frxuexi.park2302

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.mvi.BaseViewActivity
import com.frxuexi.lib_base.utils.LiveDataBus
import com.frxuexi.park2302.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

@Route(path = "/app/MainActivity")
@AndroidEntryPoint
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    override val binding: ActivityMainBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    override fun initData() {

    }

    override fun initView() {
        val controller = findNavController(R.id.fragment_main)
        NavigationUI.setupWithNavController(binding.nav,controller)

        //加红点
        val badge = binding.nav.getOrCreateBadge(R.id.messageFragment)
        badge.apply {
            number=5
            backgroundColor=Color.RED
            badgeTextColor=Color.WHITE
        }

        //点击取消气泡
        binding.nav.menu.findItem(R.id.messageFragment).setOnMenuItemClickListener {
            binding.nav.removeBadge(R.id.messageFragment)
            false
        }

        EventBus.getDefault().register(this)

        LiveDataBus.with<String>("msg").postValue("myLiveData")

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun getMsg(msg:String){
        ToastUtils.showLong(msg)
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
}